<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首页</title>
<style>
	tr:nth-child(odd){
			background: red;
	}//隔行变色
</style>
</head>
<body>
	<c:if test="${empty list }">
		<c:redirect url="SelectFinProServlet"></c:redirect>
	</c:if>
	<form method="post" action="SelectFinProServlet">
		<div>产品名称： <input type="text" name="id">
		       风险评级： 
		       <select name="risk">
					<option value="-1" selected>请选择 </option>
					<option value="1"> R1</option>
					<option value="2"> R2</option>
					<option value="3"> R3</option>
		       </select>
			   <input type="submit" name="btnSubmit" value="查找">
			   <a href="addFinPro.jsp">新增理财信息</a>
		</div>
		<br />
		<br />
		<table width=600px border=1>
			<tr>
				<th>产品代码</th>
				<th>风险评级</th>
				<th>预期收益</th>
				<th>发售起始日</th>
				<th>发售截止日</th>
				<th>到期日</th>
				<th>操作</th>
			</tr>
			<c:forEach items="${list }" var="finpro" varStatus="idx">
				<tr <c:if test="${idx.index%2 !=0 }">background:#ccc</c:if> >
					<td>${finpro.id }</td>
					<!--  <td>R${finpro.risk }</td> -->
					<td>
						<c:if test="${finpro.risk==1 }">R1</c:if>
						<c:if test="${finpro.risk==2 }">R2</c:if>
						<c:if test="${finpro.risk==3 }">R3</c:if>
					</td>
					<td>${finpro.income}</td>
					<td>${finpro.saleStarting}</td>
					<td>${finpro.saleEnd}</td>
					<td>${finpro.end}</td>
					<td>
						 <a href="UpdateFinProServlet"  >修改</a> 
						 <a href="javascript:void(0))" onclick="del(this,${finpro.id })">删除</a> 
					</td>
				</tr>
			</c:forEach>
		</table>	
	</form>
	<script src="js/jquery-1.12.4.js"></script>
<script type="text/javascript">
	function del(dom,id){
		//$.getJSON("url","param",回调函数);
		$.getJSON("DeleteFinProServelet","pid="+id ,function(data){
			
			if(data.msg ==1){
			 	//删除成功
			 	//提示 并移除该行
			 	alert("删除成功");
			 	$(dom).parent().parent().remove();
			}else{
				//不存在,可以用	
				$("#spanId").html("代码可用");
			}
		});
	}
</script>
</body>
</html>